import moment from 'moment'
import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'

// 回款信息-核销信息header
function writeoffHeaders(_this) {
  return [
    {
      type: 'index',
      title: '序号',
      width: 80
    },
    {
      field: 'writeOffAmount',
      title: '本次核销金额(元)',
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.writeOffAmount)
          })
        }
      }
    },
    {
      field: 'createTime',
      title: '核销日期',
      width: 120
    },
    {
      field: 'bonusName',
      title: '关联奖金单'
    },
    {
      field: 'handles',
      title: '操作',
      width: 90,
      slots: {
        default: (params, h) => {
          return [
            table.cell.btn(_this, h, {
              title:
                !params.row.bonusName &&
                params.row.isValid &&
                _this.unlocking('0210020601') &&
                !params.row.isImport
                  ? '作废'
                  : '',
              event: 'onCancellation',
              data: params
            }),
            h('span', !params.row.isValid ? '已废弃' : '')
          ]
        }
      }
    }
  ]
}

// 回款信息-开票信息header
function invoiceHeaders(_this) {
  return [
    {
      type: 'index',
      title: '序号',
      width: 80
    },
    {
      field: 'invoiceCode',
      title: '开票号码'
    },
    {
      field: 'invoiceDate',
      title: '开票日期',
      width: 120,
      slots: {
        default: ({ row }, h) => {
          return table.cell.text(h, {
            value: row.invoiceDate ? moment(row.invoiceDate).format('yyyy-MM-DD') : ''
          })
        }
      }
    },
    {
      field: 'invoiceAmount',
      title: '开票金额(元)',
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.invoiceAmount)
          })
        }
      }
    },
    {
      field: 'noTaxAmount',
      title: '未税金额(元)',
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.noTaxAmount)
          })
        }
      }
    },
    {
      field: 'invoiceVoucher',
      title: '发票凭证',
      width: 100,
      slots: {
        default: ({ row }, h) => {
          return table.cell.btn(_this, h, {
            title: '查看',
            event: 'onDetail',
            data: row
          })
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      width: 90,
      slots: {
        default: (params, h) => {
          return [
            table.cell.btn(_this, h, {
              title:
                !params.row.delFlag && _this.unlocking('0210020602') && !params.row.isImport ? '作废' : '',
              event: 'onCancellation',
              data: params
            }),
            h('span', params.row.delFlag ? '已废弃' : '')
          ]
        }
      }
    }
  ]
}

// 分批核销房源设置header
function batchWriteoffHeaders(_this) {
  return [
    {
      type: 'checkbox',
      fixed: 'left',
      width: 55
    },
    {
      type: 'index',
      title: '序号',
      fixed: 'left',
      width: 70
    },
    {
      field: 'roomName',
      title: '房源名称',
      fixed: 'left',
      width: 150
    },
    {
      field: 'contractDate',
      title: '签约日期',
      width: 120
    },
    {
      field: 'customerName',
      title: '客户姓名',
      width: 120
    },
    {
      field: 'productName',
      title: '产品',
      width: 150
    },
    {
      field: 'counselorName',
      title: '业务员',
      width: 120
    },
    {
      field: 'channelSourceName',
      title: '渠道来源',
      width: 120
    },
    {
      field: 'isAssociates',
      title: '是否关系户',
      width: 110,
      cell: {
        value: (row) => (row.isAssociates ? '是' : '否'),
        text: {}
      }
    },
    {
      field: 'area',
      title: '面积(m²)',
      width: 110,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'totalPrice',
      title: '签约总价(元)',
      width: 130,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'predictAccountDate',
      title: '全款到账日期',
      width: 130
    },
    {
      field: 'accumulateMoney',
      title: '累计回款金额(元)',
      width: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'actualAgentCost',
      title: '本次可结代理费(元)',
      width: 160,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'actualAgentCost',
      title: '未核销金额(元)',
      width: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    }
  ]
}

// 佣金调整header
function adjustHeaders(_this) {
  return [
    {
      type: 'index',
      title: '序号',
      width: 70
    },
    {
      key: 'adjustType',
      title: '调整类型',
      width: 140,
      slot: 'adjustType'
    },
    {
      key: 'reason',
      title: '调整原因',
      slot: 'reason'
    },
    {
      key: 'adjustAmount',
      title: '调整金额(元)',
      slot: 'adjustAmount'
    }
  ]
}

export default {
  writeoffHeaders,
  invoiceHeaders,
  batchWriteoffHeaders,
  adjustHeaders
}
